<template>
  <div class="not-found-container">
    <!-- 错误代码动画 -->
    <div class="error-code">
      <span class="digit" :style="{ animationDelay: '0ms' }">4</span>
      <span class="zero">0</span>
      <span class="digit" :style="{ animationDelay: '200ms' }">4</span>
    </div>

    <!-- 错误信息 -->
    <h1 class="error-title">页面未找到</h1>
    <p class="error-message">
      抱歉，您访问的页面不存在或已被移除。<br />
      可能是 URL 错误或页面已移动。
    </p>

    <!-- 操作按钮 -->
    <div class="action-buttons">
      <button class="btn back-btn" @click="goBack">
        <i class="fas fa-arrow-left"></i> 返回上一页
      </button>
      <button class="btn home-btn" @click="goHome"><i class="fas fa-home"></i> 返回首页</button>
    </div>

    <!-- 装饰元素 -->
    <div class="decor-elements">
      <div class="element" :style="{ top: '10%', left: '10%' }"></div>
      <div class="element" :style="{ top: '20%', right: '15%' }"></div>
      <div class="element" :style="{ bottom: '15%', left: '20%' }"></div>
      <div class="element" :style="{ bottom: '10%', right: '10%' }"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
import { onMounted } from 'vue'

const router = useRouter()

// 返回上一页
const goBack = () => {
  window.history.back()
}

// 返回首页
const goHome = () => {
  router.push('/')
}

// 添加页面载入动画
onMounted(() => {
  document.body.classList.add('not-found-page')

  return () => {
    document.body.classList.remove('not-found-page')
  }
})
</script>

<style scoped>
.not-found-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  position: relative;
  overflow: hidden;
  background-color: #f8fafc;
}

.error-code {
  font-size: 12rem;
  font-weight: 900;
  margin: 2rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}

.digit {
  color: #3b82f6;
  position: relative;
  display: inline-block;
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp 0.8s forwards;
}

.zero {
  width: 100px;
  height: 100px;
  border: 15px solid #ef4444;
  border-radius: 50%;
  position: relative;
  animation: pulse 2s infinite;
}

.zero::before {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  background-color: #ef4444;
  border-radius: 50%;
  top: 30%;
  left: 30%;
  transform: translate(-50%, -50%);
}

.error-title {
  font-size: 2.5rem;
  color: #1e293b;
  margin-bottom: 1rem;
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp 0.8s 400ms forwards;
}

.error-message {
  font-size: 1.2rem;
  color: #64748b;
  max-width: 600px;
  line-height: 1.6;
  margin-bottom: 2rem;
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp 0.8s 600ms forwards;
}

.action-buttons {
  display: flex;
  gap: 1rem;
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp 0.8s 800ms forwards;
}

.btn {
  padding: 0.8rem 1.5rem;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: none;
}

.back-btn {
  background-color: #e2e8f0;
  color: #334155;
}

.back-btn:hover {
  background-color: #cbd5e1;
  transform: translateY(-2px);
}

.home-btn {
  background-color: #3b82f6;
  color: white;
}

.home-btn:hover {
  background-color: #2563eb;
  transform: translateY(-2px);
}

.decor-elements {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.element {
  position: absolute;
  width: 30px;
  height: 30px;
  background-color: rgba(59, 130, 246, 0.1);
  border-radius: 8px;
  animation: float 8s infinite ease-in-out;
}

.element:nth-child(2) {
  width: 50px;
  height: 50px;
  animation-delay: 2s;
  animation-duration: 10s;
  background-color: rgba(239, 68, 68, 0.1);
}

.element:nth-child(3) {
  width: 20px;
  height: 20px;
  animation-delay: 4s;
  animation-duration: 6s;
  background-color: rgba(16, 185, 129, 0.1);
}

.element:nth-child(4) {
  width: 40px;
  height: 40px;
  animation-delay: 6s;
  animation-duration: 12s;
  background-color: rgba(245, 158, 11, 0.1);
}

/* 动画定义 */
@keyframes fadeInUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 0 15px rgba(239, 68, 68, 0);
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-20px) rotate(10deg);
  }
}

/* 响应式调整 */
@media (max-width: 768px) {
  .error-code {
    font-size: 8rem;
  }

  .zero {
    width: 80px;
    height: 80px;
    border-width: 12px;
  }

  .error-title {
    font-size: 2rem;
  }

  .action-buttons {
    flex-direction: column;
    width: 100%;
    max-width: 300px;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .error-code {
    font-size: 6rem;
  }

  .zero {
    width: 60px;
    height: 60px;
    border-width: 10px;
  }

  .error-title {
    font-size: 1.5rem;
  }

  .error-message {
    font-size: 1rem;
  }
}
</style>
